import Layout from '@components/layout';
import { Empty, Icon } from 'antd';
import * as React from 'react';
import Clipboard from 'react-clipboard.js';

interface IErrorProps {
	code?: number;
	err?: Error;
}

class ErrorPage extends React.Component<IErrorProps, {}> {
	static getInitialProps(param: any) {
		const code = param.res ? param.res.statusCode : param.err ? param.err.statusCode : null;
		const err = param.err;
		return {
			code,
			err
		};
	}

	public render() {
		const message = this.props.err ? "Message: " + this.props.err.message + "\nStack: " + this.props.err.stack : "";
		return (
			<Layout title="错误" className="page-error">
				<Empty
					image={<Icon type="info-circle" style={{ fontSize: 40 }} />}
					imageStyle={{ height: "50px" }}
					description={this.props.code === 404 ? "您访问的页面不存在" : "处理您的请求期间发生了一个错误，请稍后重试"}
				>
					{message ? <Clipboard component="a" data-clipboard-text={message}>复制技术细节</Clipboard> : ""}
				</Empty>
			</Layout>
		)
	}
}

export default ErrorPage